<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>提交页面</title>
    <script type="text/javascript" src="http://localhost:8080<%=request.getContextPath() %>/js/jquery-1.3.2.min.js"></script>
    <script type="text/javascript" src="http://localhost:8080<%=request.getContextPath() %>/js/ajaxfileupload.js"></script>

   
    
    <script type="text/javascript">
    
	    $(function(){
	    	//序列化转Json， $.fn.serializeJson方法只在jquery-1.3.2.min.js里有，在jquery-2.1.4.min.js里没有
		    $.fn.serializeJson=function(){
		        var serializeObj={};
		        var array=this.serializeArray();
		        var str=this.serialize();
		        $(array).each(function(){
		            if(serializeObj[this.name]){
		                if($.isArray(serializeObj[this.name])){
		                    serializeObj[this.name].push(this.value);
		                }else{
		                    serializeObj[this.name]=[serializeObj[this.name],this.value];
		                }
		            }else{
		                serializeObj[this.name]=this.value;
		            }
		        });
		        return serializeObj;
		    };
		});
		
		
    	function submitForm(){
		    var data = $("#submitDiv").serializeJson();
		    
		    
        var files = new Array();
        $('input[type="file"]').each(function() {
            files.push($(this).attr("name"));
        });
        
		    
		    
			$.ajaxFileUpload({
				url : "http://localhost:8080<%=request.getContextPath()%>/user/submitUser",
				secureuri : false,
				async: false,
				fileElementId : files,
				dataType : 'json',
				data : data,
				success : function(res) {
				alert(res.result);
					alert("成功");
				},
				error: function(res) {
					alert("操作失败,请稍后再试！");
				}
			});
		}
</script>
	
  </head>
  
  <body>
  提交页面：
  <form id="submitDiv">
	    userName:<input type="text" name="username" id="username"><br>
	    password:<input type="text" name="password" id="password"><br>
	    account:<input type="text" name="account" id="account"><br>
  </form>
  文件1：    <input type="file" name="uploadFile1" id="uploadFile1">
文件2：    <input type="file" name="uploadFile2" id="uploadFile2">
  <input type="button" value="提交" onclick="submitForm();"/>
    
  </body>
</html>